package com.vegetable.modules.service.baseData.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.modules.entity.baseData.FundAccountDetail;
import com.vegetable.modules.entity.baseData.po.FundAccountDetailPO;
import com.vegetable.modules.mapper.baseData.FundAccountDetailMapper;
import com.vegetable.modules.service.baseData.IFundAccountDetailService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 资金账户 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-04
 */
@Slf4j
@Service
@AllArgsConstructor
public class FundAccountDetailServiceImpl extends ServiceImpl<FundAccountDetailMapper, FundAccountDetail> implements IFundAccountDetailService {

    @Override
    public IPage<FundAccountDetail> detailList(FundAccountDetailPO po) {
        Page<FundAccountDetail> page = new Page<>(po.getCurrent(), po.getSize());
        QueryWrapper<FundAccountDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(po.getAccountId()), "account_id", po.getAccountId());
        queryWrapper.like(StringUtils.isNotBlank(po.getAccountName()), "account_name", po.getAccountName());
        queryWrapper.eq(!Objects.isNull(po.getChangeType()), "change_type", po.getChangeType());
        queryWrapper.lt(!Objects.isNull(po.getCreateTimeEnd()), "create_time", po.getCreateTimeEnd());
        queryWrapper.gt(!Objects.isNull(po.getCreateTimeStart()), "create_time", po.getCreateTimeStart());
        queryWrapper.orderByDesc("create_time");
        IPage<FundAccountDetail> result = baseMapper.selectPage(page, queryWrapper);
        return result;
    }
}
